package com.ruike.alisurface.ui.settings;

import android.content.ComponentName;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ActivityUtils;
import com.ruike.alisurface.R;
import com.ruike.alisurface.base.BaseAty;
import com.ruike.alisurface.bean.SettingPageItemBean;
import com.ruike.alisurface.ui.adapters.SettingPageAdapter;
import com.ruike.alisurface.utils.ShareKey;
import com.voodoo.lib_frame.manager.ActivityManager;
import com.voodoo.lib_utils.SharedUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Description：设置界面
 */
public class Settings_Aty extends BaseAty implements SettingPageAdapter.OnSettingItemClickListener {

    @BindView(R.id.setting_goback_tv)
    TextView settingGobackTv;
    @BindView(R.id.setting_exitApp_tv)
    TextView settingExitAppTv;
    @BindView(R.id.setting_connect_recv)
    RecyclerView settingConnectRecv;
    List<SettingPageItemBean> settingPageItemBeans;
    SettingPageAdapter adapter;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initViews() {
        initTitleBar(false);
    }

    @Override
    protected void initData() {
        startCountdownTimer(60, null, null);

        settingPageItemBeans = new ArrayList<>();
        settingPageItemBeans.add(new SettingPageItemBean(1, R.mipmap.icon_setting, getResources().getString(R.string.baseSettingStr)));
        settingPageItemBeans.add(new SettingPageItemBean(2, R.mipmap.icon_slot, getResources().getString(R.string.slotTestStr)));

        settingPageItemBeans.add(new SettingPageItemBean(4, R.mipmap.icon_door, getResources().getString(R.string.Open_theelectronicdoorlock)));
        settingPageItemBeans.add(new SettingPageItemBean(6, R.mipmap.icon_replenishment, getResources().getString(R.string.replenishment_settings)));
        settingPageItemBeans.add(new SettingPageItemBean(8, R.mipmap.icon_face, getResources().getString(R.string.change_alface_setting)));

        settingPageItemBeans.add(new SettingPageItemBean(9, R.mipmap.icon_shouhu, getResources().getString(R.string.appDaemonStr)));
//        settingPageItemBeans.add(new SettingPageItemBean(10, R.mipmap.icon_other, getResources().getString(R.string.otherSettingsStr)));
        adapter = new SettingPageAdapter(this, settingPageItemBeans);
        adapter.setOnSettingItemClickListener(this);
        settingConnectRecv.setLayoutManager(new GridLayoutManager(this, 2));
        settingConnectRecv.setAdapter(adapter);
    }

    @OnClick({R.id.setting_goback_tv, R.id.setting_exitApp_tv})
    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.setting_goback_tv:

                startCountdownTimer(0, null, null);

                break;
            case R.id.setting_exitApp_tv:
                // 停止服务退出APP
                //点击的时候发送一条广播出去
                Intent intent = new Intent("com.MainApp.Action.Exit"); // 发送APP退出的广播
                intent.setComponent(new ComponentName("com.voodoo.appdaemon", "com.voodoo.appdaemon.MyReceiver")); // 括号里为包名+广播类
                sendBroadcast(intent);
                ActivityManager.getInstance().killAllActivity(true);
                finish();
                break;
        }
    }


    @Override
    public void onSettingItemClick(SettingPageItemBean settingPageItemBean, int index) {
        switch (settingPageItemBean.getFlag()) {
            case 1: // 基础设置
                startActivity(BaseSetting_Aty.class, null);
                break;
            case 2: // 货道检测
                startActivity(SlotTest_Aty.class, null);
                break;
            case 4: // 开启电控锁门
                startActivity(OpenDoor_Aty.class, null);
                break;
            case 5: //语言
//                startActivity(ChangeLanguageActivity.class, null);
                break;
            case 6: // 补货设置
                startActivity(ReplenishmentMag_Aty.class, null);
                break;
            case 7: // 换肤
//                startActivity(ChangeSknipeelerActivity.class, null);
                break;
            case 8: //
                startActivity(AliFaceTest_Aty.class, null);
                break;

            case 9: //   守护设置
                startActivity(AppDaemon_Aty.class, null);
                break;
            case 10: //  其他设置
                startActivity(OtherSetting_Aty.class, null);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (settingPageItemBeans!=null){
            settingPageItemBeans.clear();
            settingPageItemBeans=null;
        }
        if (adapter!=null){
            adapter=null;
        }
    }
}
